package com.qingke.notlonely.command.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.qingke.notlonely.bean.User;
import com.qingke.notlonely.bean.UserEduction;
import com.qingke.notlonely.command.SystemCommand;
import com.qingke.notlonely.util.NLConsole;

public class ListUserAndEductionByHighestDegree extends SystemCommand{

	@Override
	public void execute() {
		List<User> listU=dao.selectUser();
		List<UserEduction> listUE=dao.selectUserEduction();
		Map<User,Integer> map=new HashMap<>();
		for(User u:listU){
			int highest=0;
			for(UserEduction ue:listUE){
				if(ue.getUser().getId()==u.getId())
					highest=Math.max(highest, ue.getEduction().getDegree().getLevel());
			}
			map.put(u, highest);
		}
		
		for(User u:listU){
			NLConsole.println(u);
			for(UserEduction ue:listUE){
				if(ue.getUser().getId()==u.getId()
						&&ue.getEduction().getDegree().getLevel()==map.get(u))
					NLConsole.println(ue.getEduction());
			}
			NLConsole.println();
		}
	}

}
